package programs.statement;

import java.util.*;

import programs.expression.implementedClasses.Variable;
import game.Ship;

public abstract class ComposedStatement extends Statement {
	
	public abstract int getNbOfSubStatements();
	
	public abstract List<Statement> getAllSubStatements();
	
	public Set<Variable> getVariables() {
		Set<Variable> set = new HashSet<Variable>();
		for(Statement statement : getAllSubStatements()) {
			set.addAll(statement.getVariables());
		}
		return set;
	}
	

	@Override
	public boolean isValidStatement() {
		for(Statement subStatement : getAllSubStatements())
			if(! subStatement.isValidStatement())
				return false;
		return true;
	}

	@Override
	public boolean containsAction() {
		for(Statement subStatement : getAllSubStatements())
			if(subStatement.containsAction())
				return true;
		return false;
	}
	
	@Override
	public void setExecuter(Ship executer) {
		super.setExecuter(executer);
		for(Statement sub : getAllSubStatements()) 
			sub.setExecuter(executer);
	}
	
	@Override
	public void assignGlobalVariable(Variable variable) {
		for(Statement sub : getAllSubStatements())
			sub.assignGlobalVariable(variable);
	}
	
	@Override
	public boolean isEmpty() {
		for(Statement sub : getAllSubStatements())
			if(! sub.isEmpty())
				return false;
		return true;
	}
}
